﻿/**
 * @file DyByteBuffTest.cc
 * @brief test of dynamic byte buffer
 * $Id: DyByteBuffTest.cc 6 2010-07-13 10:51:30Z tonyjobmails $
 * $Date: 2010-07-13 18:51:30 +0800 (二, 13  7月 2010) $
 * $Author: tonyjobmails $
 * $Revision: 6 $
 */

#include <strings.h>
#include <string.h>
#include "DyByteBuff.h"

void TestDyByteBuff()
{
	DyByteBuff buff;
	unsigned char data[11] = "123456789";
	buff.write(static_cast<const unsigned char *>(data), 9);
	log::_DEBUG_LOG("BUFF read size: %u", buff.rd_size());

	buff.disp();

	std::vector<unsigned char> strings;
	strings.resize(buff.rd_size() + 1);
	bcopy(buff.rd_ptr(), &strings[0], buff.rd_size());
	strings.push_back('\0');

	buff.disp();
	log::_DEBUG_LOG("data of the BUFF is: %s", &strings[0]);

	memcpy(data, "aaaaaaa", sizeof(data));
	buff.write(static_cast<const unsigned char *>(data), 7);
	log::_DEBUG_LOG("BUFF read size: %u", buff.rd_size());

	strings.resize(buff.rd_size() + 1);
	bcopy(buff.rd_ptr(), &strings[0], buff.rd_size());
	strings.push_back('\0');

	buff.disp();
	log::_DEBUG_LOG("data of the BUFF is: %s", &strings[0]);
};
